﻿
//======================================================================
//
//        Copyright (C) 2016   
//        All rights reserved
//
//        filename : StorageDetailedList
//        description : 白卡出库明细
//        created by zhouhaijun at  20161009
//
//======================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CardLogistics.Web.Components;
using System.Text;

using System.Data.OleDb;
using System.IO;
using CardLogistics.Model.CardArrival;

namespace CardLogistics.Web.MainPage.PutOutCard.PutOutCard
{
    public partial class PutOutCardDetailsList : BasePage
    {
        /// <summary>
        /// 箱数
        /// </summary>
        public int BoxNumber
        {
            get;
            set;
        }
        /// <summary>
        /// 盒数
        /// </summary>
        public int CardNumber
        {
            get;
            set;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDLL(ddlsupName, "basic_suppliers", "suppliersname", "suppliersid", " and STATUS=0 and ISDELETE=0");  //供应商
                BindDLL(ddlCardType, "basic_cardtype", "cardtypename", "id", " and  status<>1 and isdelete=0"); //卡片类型
                BindDLL(ddlBtypename, "basic_basictype", "typename", "ID", " and typeno=0 and ISDELETE=0  ");//绑定芯片类型
                BindRpt(LoadStrWhere);
            }
        }

        /// <summary>
        /// 绑定Rpt数据
        /// </summary>
        private void BindRpt(string strWhere)
        {
            int recordCount = 0;
            int pageCount = 0;
            StringBuilder sbStr = new StringBuilder();
            sbStr.Append(" 1=1 ");
            //出库单号
            if (!string.IsNullOrEmpty(this.txtOutStorageNo.Text.Trim()) && txtOutStorageNo.Text.Trim().Length > 0)
                sbStr.Append(" and putoutcardno like '%" + txtOutStorageNo.Text.Trim().ToUpper() + "%' ");
            //申领单号
            if (!string.IsNullOrEmpty(this.txtAPPLYNO.Text.Trim()) && txtAPPLYNO.Text.Trim().Length > 0)
                sbStr.Append(" and APPLYNO like '%" + txtAPPLYNO.Text.Trim().ToUpper() + "%' ");
            if (txt_StartStorageDate.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(putoutcarddate,'yyyy-MM-dd')>='" + txt_StartStorageDate.Text.Trim() + "'");//出库开始日期
            if (txt_EndStorageDate.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(putoutcarddate,'yyyy-MM-dd')<='" + txt_EndStorageDate.Text.Trim() + "'");//出库结束日期
            //供应商
            if (this.ddlsupName.SelectedItem != null && ddlsupName.SelectedIndex != 0)
            {
                sbStr.Append(" and SuppId='" + ddlsupName.SelectedValue.ToString() + "'");
            }
            //卡片类型
            if (this.ddlCardType.SelectedItem != null && ddlCardType.SelectedValue != "" && ddlCardType.SelectedValue != "0")
            {
                sbStr.Append(" and CardTypeId='" + ddlCardType.SelectedValue + "'");
            }
            //卡芯片
            if (this.ddlBtypename.SelectedItem!=null && this.ddlBtypename.SelectedIndex != 0)
            {
                sbStr.Append(" and basictypeid='" + this.ddlBtypename.SelectedValue.ToString() + "'");//芯片类型
            }
            if (!string.IsNullOrEmpty(strWhere))
            {
                sbStr.Append(strWhere);
            }
            DataTable dt = CardLogistics.DAL.CommonData.QuickPage_Oracle("v_putoutcard_detail", "ID", " putoutcardno desc", AspNetPager1.PageSize, WebPageIndex, sbStr.ToString(), "*", out pageCount, out recordCount);
            SetNetPagerHtml(AspNetPager1, dt, rptList, recordCount);

            #region 导出数据
            //导出语句
            string strExpSql = "select putoutcarddate 出库日期,putoutcardno 出库单号,APPLYNO 申领单号,suppliersname 供应商,Cardtypename 卡类型,TypeName 芯片类型,CARDNO 盒号,FGVAMT 卡成本,STARTCARDNO 开始卡号,ENDCARDNO 结束卡号,DUENUMBER 应有数量,ACTUALNUMBER 实际数量 ,MISSINGCARDNO 缺省卡号 from v_putoutcard_detail where " + sbStr.ToString() + "order by putoutcardno desc";
            if (!Page.IsClientScriptBlockRegistered("regExportSql"))
                Page.RegisterClientScriptBlock("regExportSql", "<script language=\"Javascript\">var qsql=\"" + Server.UrlEncode(strExpSql) + "\";</script>");
            #endregion
        }


        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            WebPageIndex = AspNetPager1.CurrentPageIndex;
            BindRpt("");
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            WebPageIndex = 1;
            BindRpt("");
        }
    }
}